package com.zxh.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import com.zxh.dao.CompanyDao;
import com.zxh.entity.Company;

@WebServlet("/comp.do")
public class CompanyServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
			HttpSession session = req.getSession();
			String type = req.getParameter("type");//表示保存的类型
			PrintWriter out= resp.getWriter();
			int applicant_id=0;
			if(session.getAttribute("applicant_id")!=null){
				applicant_id = (Integer) session.getAttribute("applicant_id");
			}
			Company company = getRequestData(req);
			CompanyDao compDao = new CompanyDao();
			JSONObject json = new JSONObject();
			if("save".equals(type)){
				try {
					
				} catch (Exception e) {
					// TODO: handle exception
				}
			}
			
		/*	
		 * 测试“在线编辑器”是否成功使用
		 * String editvalue = req.getParameter("editorValue");
			String company_name = req.getParameter("company_name");
			System.out.println("editvalue:"+editvalue);
			System.out.println("company_name:"+company_name);*/
	
	}
	
	private Company getRequestData(HttpServletRequest req){
		 HttpSession session = req.getSession();
		 String company_name=req.getParameter("company_name");//公司名称
		 String company_area=req.getParameter("company_area");//公司所在地区
		 String company_size=req.getParameter("company_size");//公司规模
		 String company_type=req.getParameter("company_type");//公司性质
		 String company_brief=req.getParameter("company_brief");//公司简介
		 int applicant_id=0;
		 if(session.getAttribute("applicant_id")!=null){
			 applicant_id = (Integer) session.getAttribute("applicant_id");
		 }
		 //???????????????
		 Company company = new Company(applicant_id, applicant_id, company_name,company_area,company_size,company_type,company_brief, applicant_id, applicant_id, applicant_id, company_brief);
		 return company;
		 
	}
	
	
}
